package org.example.kg_back.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.kg_back.PoJo.entity.Atc;
import org.example.kg_back.PoJo.entity.MultiRadar;
import org.example.kg_back.mapper.AtcMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


@Service
public class AtcService extends ServiceImpl<AtcMapper, Atc> {

	@Autowired
	private MultiRadarService multiRadarService;

	/**
	 * 查询所有扇区航班架次
	 * @return
	 */
	public List<Atc> findSectorSortie() {

        return baseMapper.findSectorSortie();
	}


	/**
	 * 根据扇区号查询架次
	 *
	 * @param planSectorName
	 * @return
	 */
	public int findLocusCount(String planSectorName) {

		QueryWrapper<MultiRadar> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("section",planSectorName);
        return multiRadarService.count(queryWrapper);

	}


	/**
	 * 扇区架次数动态统计(饼状图)
	 * @return
	 */
	public List<ArrayList<Object>> findATCTime() {
		List<String> sectorName = new ArrayList<>();
		sectorName.add("K");
		sectorName.add("S");
		sectorName.add("E");
		sectorName.add("P");
		sectorName.add("G");
		List<String> executeTime = baseMapper.findATCTime();

		List<ArrayList<Object>> list = new ArrayList<>();
        for (String s : executeTime) {
            ArrayList<Object> objects = new ArrayList<>();
            for (String string : sectorName) {
                Atc atcTime2 = baseMapper.findATCTime2(s, string);
                HashMap<String, Object> map = new HashMap<>();
                if (atcTime2.getPlanSectorName() != null) {
                    map.put(atcTime2.getPlanSectorName(), atcTime2.getCount());
                } else {
                    map.put(string, 0);
                }
                objects.add(map);
            }
            list.add(objects);
        }

		return list;
	}

}
